Add the minimum_points option to trackfilter for OSM users.
authorRobert Lipe <robertlipe@gpsbabel.org>
Fri, 30 Dec 2016 00:27:24 +0000 (18:27 -0600)
committerRobert Lipe <robertlipe@gpsbabel.org>
Fri, 30 Dec 2016 00:27:24 +0000 (18:27 -0600)
trackfilter.cc
xmldoc/filters/options/track-minimum_points.xml [new file with mode: 0644]

index aff04c14dd0ee4a0de902eddfacac731f5910d04..9005f89037d3c7317a63114925908ef09882daee 100644 (file)
@@ -52,6 +52,7 @@
 #define TRACKFILTER_SEGMENT_OPTION      "segment"
 #define TRACKFILTER_FAKETIME_OPTION     "faketime"
 #define TRACKFILTER_DISCARD_OPTION      "discard"
+#define TRACKFILTER_MINPOINTS_OPTION    "minimum_points"
 
 #undef TRACKF_DBG
 
@@ -72,6 +73,7 @@ static char* opt_trk2seg = NULL;
 static char* opt_segment = NULL;
 static char* opt_faketime = NULL;
 static char* opt_discard = NULL;
+static char* opt_minpoints = NULL;
 
 static
 arglist_t trackfilter_args[] = {
@@ -156,6 +158,11 @@ arglist_t trackfilter_args[] = {
     "Discard track points without timestamps during merge",
     NULL, ARGTYPE_BOOL, ARG_NOMINMAX
   },
+  {
+    TRACKFILTER_MINPOINTS_OPTION, &opt_minpoints,
+    "Discard tracks with fewer than these points",
+    NULL, ARGTYPE_INT, "0"
+  },
   ARG_TERMINATOR
 };
 
@@ -311,7 +318,7 @@ trackfilter_fill_track_list_cb(const route_head* track)     /* callback for track_d
   Waypoint* wpt, *prev;
   queue* elem, *tmp;
 
-  if (track->rte_waypt_ct == 0) {
+  if (track->rte_waypt_ct == 0 ) {
     track_del_head((route_head*)track);
     return;
   }
@@ -364,6 +371,16 @@ trackfilter_fill_track_list_cb(const route_head* track)    /* callback for track_d
   track_ct++;
 }
 
+static void
+trackfilter_minpoint_list_cb(const route_head* track)
+{
+  int minimum_points = atoi(opt_minpoints);
+  if (track->rte_waypt_ct < minimum_points ) {
+    track_del_head((route_head*)track);
+    return;
+  }
+}
+
 /*******************************************************************************
 * track title producers
 *******************************************************************************/
@@ -458,7 +475,7 @@ trackfilter_pack(void)
     prev = track_list[j];
     if (prev.last_time >= track_list[i].first_time) {
       fatal(MYNAME "-pack: Tracks overlap in time! %s >= %s at %d\n",
-        qPrintable(prev.last_time.toString()), 
+        qPrintable(prev.last_time.toString()),
         qPrintable(track_list[i].first_time.toString()), i);
     }
   }
@@ -1375,6 +1392,11 @@ trackfilter_process(void)
 
     trackfilter_split();
   }
+
+  // Performed last as previous options may have created "small" tracks.
+  if ((opt_minpoints != NULL) && atoi(opt_minpoints) > 0) {
+    track_disp_all(trackfilter_minpoint_list_cb, NULL, NULL);
+  }
 }
 
 /******************************************************************************************/
diff --git a/xmldoc/filters/options/track-minimum_points.xml b/xmldoc/filters/options/track-minimum_points.xml
new file mode 100644 (file)
index 0000000..31b79a9
--- /dev/null
@@ -0,0 +1,8 @@
+<para>
+Eliminates any remaining tracks with fewer than this number of trackpoints.
+</para>
+<para>
+This step is performed last by this filter and is used to clean up earlier
+simplifications that may have left tracks with so few points as to be 
+useless, such as a track taken while stationary but with GPS wander.
+</para>